#ifndef VIRTUALCAR_H
#define VIRTUALCAR_H


#include<QTcpSocket>

#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui { class VirtualCar; }
QT_END_NAMESPACE

struct Line{
    Line(const int &id):id(id){}
    int id;
    int start,end;
};
struct Node{
    Node(const int &id):id(id){}
    int id;
    QList<int>out_roads_id;
    QList<int>in_roads_id;
};

class VirtualCar : public QWidget
{
    Q_OBJECT

public:

    //VirtualCar(QWidget *parent = nullptr);
     explicit VirtualCar(const int &id,QWidget *parent = nullptr);
    ~VirtualCar();

protected:
    void paintEvent(QPaintEvent *e)override;

private slots://槽函数声明
    void slot_stateChanged(QAbstractSocket::SocketState state);
    void slot_move();
    void slot_readyRead();

private:
    void init();

    void sendId();//发送身份信息

    void sendState();//发送车的状态：所处道路

    void SendGetCrossState();//获取路口状态

    //  QList<QJsonObiect>splitJsonQbjects(const QByteArray &data);
    QList<QJsonObject>splitJsonObjects(const QByteArray &data);
    Ui::VirtualCar *ui;
    QTcpSocket socket;
    const int id;
    int road_id;//处在哪条道路上
    float duration;//进度

    //容器
    QList<Line>list_line;
    QList<Node>list_node;

    QTimer *timer;
};
#endif // VIRTUALCAR_H
